using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.IO;


namespace App3._
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void prevDrag(object sender, DragEventArgs args)
        {
            if (IsSingleFile(args) != null)
                args.Effects = DragDropEffects.Copy;
            else
                args.Effects = DragDropEffects.None;

            args.Handled = true;
        }

        private void prevDrop(object sender, DragEventArgs args)
        {
            args.Handled = true;

            string filename = IsSingleFile(args);
            if (filename == null)
                return;

            StreamReader reader = new StreamReader(filename);
            textBox.Text = reader.ReadToEnd();
            reader.Close();
        }

        private string IsSingleFile(DragEventArgs args)
        {
            if (args.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                string[] filenames = args.Data.GetData(DataFormats.FileDrop, true) as string[];
                if (filenames.Length == 1)
                {
                    if (File.Exists(filenames[0]))
                        return filenames[0];
                }
            }
            return null;
        }
    }
}